/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package rigo.ricard.pris.rs.ac.uns.dmi.model;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.exception.SystemException;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.model.BaseModel;
import com.liferay.portal.model.impl.BaseModelImpl;
import com.liferay.portal.util.PortalUtil;

import rigo.ricard.pris.rs.ac.uns.dmi.service.AdvertisingLocalServiceUtil;

import java.io.Serializable;

import java.lang.reflect.Proxy;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Rigo Richard
 */
public class AdvertisingClp extends BaseModelImpl<Advertising>
	implements Advertising {
	public AdvertisingClp() {
	}

	public Class<?> getModelClass() {
		return Advertising.class;
	}

	public String getModelClassName() {
		return Advertising.class.getName();
	}

	public long getPrimaryKey() {
		return _adId;
	}

	public void setPrimaryKey(long primaryKey) {
		setAdId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return new Long(_adId);
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey(((Long)primaryKeyObj).longValue());
	}

	@Override
	public Map<String, Object> getModelAttributes() {
		Map<String, Object> attributes = new HashMap<String, Object>();

		attributes.put("adId", getAdId());
		attributes.put("userId", getUserId());
		attributes.put("userName", getUserName());
		attributes.put("createDate", getCreateDate());
		attributes.put("modifiedDate", getModifiedDate());
		attributes.put("carManufacturerId", getCarManufacturerId());
		attributes.put("carModelId", getCarModelId());
		attributes.put("carDescription", getCarDescription());
		attributes.put("location", getLocation());
		attributes.put("price", getPrice());

		return attributes;
	}

	@Override
	public void setModelAttributes(Map<String, Object> attributes) {
		Long adId = (Long)attributes.get("adId");

		if (adId != null) {
			setAdId(adId);
		}

		Long userId = (Long)attributes.get("userId");

		if (userId != null) {
			setUserId(userId);
		}

		String userName = (String)attributes.get("userName");

		if (userName != null) {
			setUserName(userName);
		}

		Date createDate = (Date)attributes.get("createDate");

		if (createDate != null) {
			setCreateDate(createDate);
		}

		Date modifiedDate = (Date)attributes.get("modifiedDate");

		if (modifiedDate != null) {
			setModifiedDate(modifiedDate);
		}

		Long carManufacturerId = (Long)attributes.get("carManufacturerId");

		if (carManufacturerId != null) {
			setCarManufacturerId(carManufacturerId);
		}

		Long carModelId = (Long)attributes.get("carModelId");

		if (carModelId != null) {
			setCarModelId(carModelId);
		}

		String carDescription = (String)attributes.get("carDescription");

		if (carDescription != null) {
			setCarDescription(carDescription);
		}

		String location = (String)attributes.get("location");

		if (location != null) {
			setLocation(location);
		}

		Double price = (Double)attributes.get("price");

		if (price != null) {
			setPrice(price);
		}
	}

	public long getAdId() {
		return _adId;
	}

	public void setAdId(long adId) {
		_adId = adId;
	}

	public long getUserId() {
		return _userId;
	}

	public void setUserId(long userId) {
		_userId = userId;
	}

	public String getUserUuid() throws SystemException {
		return PortalUtil.getUserValue(getUserId(), "uuid", _userUuid);
	}

	public void setUserUuid(String userUuid) {
		_userUuid = userUuid;
	}

	public String getUserName() {
		return _userName;
	}

	public void setUserName(String userName) {
		_userName = userName;
	}

	public Date getCreateDate() {
		return _createDate;
	}

	public void setCreateDate(Date createDate) {
		_createDate = createDate;
	}

	public Date getModifiedDate() {
		return _modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		_modifiedDate = modifiedDate;
	}

	public long getCarManufacturerId() {
		return _carManufacturerId;
	}

	public void setCarManufacturerId(long carManufacturerId) {
		_carManufacturerId = carManufacturerId;
	}

	public long getCarModelId() {
		return _carModelId;
	}

	public void setCarModelId(long carModelId) {
		_carModelId = carModelId;
	}

	public String getCarDescription() {
		return _carDescription;
	}

	public void setCarDescription(String carDescription) {
		_carDescription = carDescription;
	}

	public String getLocation() {
		return _location;
	}

	public void setLocation(String location) {
		_location = location;
	}

	public double getPrice() {
		return _price;
	}

	public void setPrice(double price) {
		_price = price;
	}

	public BaseModel<?> getAdvertisingRemoteModel() {
		return _advertisingRemoteModel;
	}

	public void setAdvertisingRemoteModel(BaseModel<?> advertisingRemoteModel) {
		_advertisingRemoteModel = advertisingRemoteModel;
	}

	public void persist() throws SystemException {
		if (this.isNew()) {
			AdvertisingLocalServiceUtil.addAdvertising(this);
		}
		else {
			AdvertisingLocalServiceUtil.updateAdvertising(this);
		}
	}

	@Override
	public Advertising toEscapedModel() {
		return (Advertising)Proxy.newProxyInstance(Advertising.class.getClassLoader(),
			new Class[] { Advertising.class }, new AutoEscapeBeanHandler(this));
	}

	@Override
	public Object clone() {
		AdvertisingClp clone = new AdvertisingClp();

		clone.setAdId(getAdId());
		clone.setUserId(getUserId());
		clone.setUserName(getUserName());
		clone.setCreateDate(getCreateDate());
		clone.setModifiedDate(getModifiedDate());
		clone.setCarManufacturerId(getCarManufacturerId());
		clone.setCarModelId(getCarModelId());
		clone.setCarDescription(getCarDescription());
		clone.setLocation(getLocation());
		clone.setPrice(getPrice());

		return clone;
	}

	public int compareTo(Advertising advertising) {
		long primaryKey = advertising.getPrimaryKey();

		if (getPrimaryKey() < primaryKey) {
			return -1;
		}
		else if (getPrimaryKey() > primaryKey) {
			return 1;
		}
		else {
			return 0;
		}
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		AdvertisingClp advertising = null;

		try {
			advertising = (AdvertisingClp)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		long primaryKey = advertising.getPrimaryKey();

		if (getPrimaryKey() == primaryKey) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return (int)getPrimaryKey();
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(21);

		sb.append("{adId=");
		sb.append(getAdId());
		sb.append(", userId=");
		sb.append(getUserId());
		sb.append(", userName=");
		sb.append(getUserName());
		sb.append(", createDate=");
		sb.append(getCreateDate());
		sb.append(", modifiedDate=");
		sb.append(getModifiedDate());
		sb.append(", carManufacturerId=");
		sb.append(getCarManufacturerId());
		sb.append(", carModelId=");
		sb.append(getCarModelId());
		sb.append(", carDescription=");
		sb.append(getCarDescription());
		sb.append(", location=");
		sb.append(getLocation());
		sb.append(", price=");
		sb.append(getPrice());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(34);

		sb.append("<model><model-name>");
		sb.append("rigo.ricard.pris.rs.ac.uns.dmi.model.Advertising");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>adId</column-name><column-value><![CDATA[");
		sb.append(getAdId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userId</column-name><column-value><![CDATA[");
		sb.append(getUserId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>userName</column-name><column-value><![CDATA[");
		sb.append(getUserName());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createDate</column-name><column-value><![CDATA[");
		sb.append(getCreateDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>modifiedDate</column-name><column-value><![CDATA[");
		sb.append(getModifiedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>carManufacturerId</column-name><column-value><![CDATA[");
		sb.append(getCarManufacturerId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>carModelId</column-name><column-value><![CDATA[");
		sb.append(getCarModelId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>carDescription</column-name><column-value><![CDATA[");
		sb.append(getCarDescription());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>location</column-name><column-value><![CDATA[");
		sb.append(getLocation());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>price</column-name><column-value><![CDATA[");
		sb.append(getPrice());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private long _adId;
	private long _userId;
	private String _userUuid;
	private String _userName;
	private Date _createDate;
	private Date _modifiedDate;
	private long _carManufacturerId;
	private long _carModelId;
	private String _carDescription;
	private String _location;
	private double _price;
	private BaseModel<?> _advertisingRemoteModel;
}